//player meta functions
local meta = FindMetaTable("Player")
if (!meta) then return end

function meta:Drunk(bool)

	self:SetNWBool("drunk", bool)

end

local chairs = {

	"models/props_c17/FurnitureChair001a.mdl",
	"models/props_c17/chair_office01a.mdl",
	"models/props_combine/breenchair.mdl",
	"models/props_furniture/chair1.mdl",
	"models/props_furniture/chair2.mdl",
}

function meta:DecrNWInt(name)

	if (self:GetNWInt(name) > 0) then

		self:SetNWInt(name, self:GetNWInt("hunger") - 1)
		
		return true
		
	else
	
		return false
		
	end
	
end

if (SERVER) then

	function meta:Think()

		if (!self.dmgTime) then self.dmgTime = 0 end
		if (!self.hungerUpdateTime) then self.hungerUpdateTime = 0 end
		if (!self.thirstUpdateTime) then self.thirstUpdateTime = 0 end
		
		
		if (CurTime() > self.dmgTime) then
		
			if (self:IsDying()) then
			
				self:TakeDamage(1, self)

			end

			self.dmgTime = CurTime() + 1
			
		end
		
		if (CurTime() > self.hungerUpdateTime) then
		
			if (self:Alive()) then
			
				if (!self:DecrNWInt("hunger") && !self:IsDying()) then
				
					self:TakeDamage(math.random(10, 15), self)
				
				end
			
			end
			
			self.hungerUpdateTime = CurTime() + 5
		
		end
		
		if (CurTime() > self.thirstUpdateTime) then
		
			if (self:Alive()) then
			
				if (!self:DecrNWInt("thirst") && !self:IsDying()) then
				
					self:TakeDamage(math.random(15, 25), self)
				
				end
			
			end
			
			self.thirstUpdateTime = CurTime() + 10
		
		end	

	end
	
end

function meta:IsDying()

	if (self:Alive() && self:Health() <= 30) then
	
		return true
	
	end
	
	return false
	
end

function meta:CanUse(ent)

	if (self:Alive() && !self:InVehicle() && ent:IsValid() && ent:GetPhysicsObject():IsValid() &&
	self:GetPos():Distance(ent:GetPos()) < 100) then

		return true
	
	end
	
	return false

end

function meta:CleanUp()

	self.sitting = false

end


function meta:AddNWInt(name, amount, tfunc, ffunc)

	local nwint = self:GetNWInt(name)

	if ((nwint + amount) > 100) then
		
		if (ffunc) then
		
			ffunc(self)
			
		end
		
		return false
		
	else
	
		self:SetNWInt(name, nwint + amount)
		
		if (tfunc) then
		
			tfunc(self)
			
		end
		
		return true
		
	end
	
end